package ic.distribution.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ic.distribution.domain.DTO.CountDTO;
import ic.distribution.domain.DTO.VehicleDTO;
import ic.distribution.domain.Vehicle;
import ic.distribution.mapper.VehicledeploymentMapper;
import ic.distribution.service.VehicledeploymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VehicledeploymentServiceImpl implements VehicledeploymentService {

    @Autowired
    private VehicledeploymentMapper vehicledeploymentMapper;

    @Override
    public PageInfo<Vehicle> searchVehicleDeploymentTasks(VehicleDTO vehicleDTO) {
        PageHelper.startPage(vehicleDTO.getPageNum(), vehicleDTO.getPageSize());
        List<Vehicle> list = vehicledeploymentMapper.searchVehicleDeploymentTasks(vehicleDTO);
        PageInfo<Vehicle> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void add(Vehicle vehicle) {
        try {
            vehicledeploymentMapper.add(vehicle);
        }catch (Exception e){
            throw new RuntimeException("服务器内部问题：添加失败");
        }

    }

    @Override
    public void updstatu(Integer id) {
        try {
            vehicledeploymentMapper.updstatu(id);
        }catch (Exception e){
            throw new RuntimeException("服务器内部问题：删除失败");
        }

    }

    @Override
    public void update(Vehicle vehicle) {
        try {
            vehicledeploymentMapper.update(vehicle);
        }catch (Exception e){
            throw new RuntimeException("服务器内部问题：修改失败");
        }

    }

    @Override
    public List<CountDTO> findVehicledeploymentCount() {
        return vehicledeploymentMapper.findVehicledeploymentCount();
    }

    @Override
    public void updcarstatu(Integer id) {
        Integer updcarstatu = vehicledeploymentMapper.updcarstatu(id);
        if (updcarstatu <= 0) {
            throw new RuntimeException("测控异常请稍后再试");
        }
    }
}
